/*
 * @lc app=leetcode.cn id=202 lang=java
 *
 * [202] 快乐数
 */

// @lc code=start
class Solution {
    public boolean isHappy(int n) {
        int p = n;
        int q = n;
        while(true){
            p = caculate(p);
            q = caculate(caculate(q));
            System.out.println("p:"+p+",\tq:"+q);
            if(1==q || 1==caculate(q)){
                return true;
            }else if(p==q){
                return false;
            }
        }
    }
    public int caculate(int n){
        int res = 0;
        while(n!=0){
            res += (n%10)*(n%10);
            n = n/10;
        }
        return res;
    }
}
// @lc code=end

